<?php

namespace app\rest\validate;

use think\Validate;

class User extends Validate
{
    protected $rule = [
        'name' => ['require', 'min'=>2, 'max'=>20],
        'sex' => ['in'=>'0,1,2'],
        'age' => ['number', 'between'=>'1,120'],
        'tel' => ['require', 'regex' => '/^1[^012]\d{9}$/'],
        'status' => ['checkStatus']
    ];

    protected $message = [
        'name.require' => '你四不四忘了填写帐号了!',
        'name.min' => '你也太短了吧!!',
        'age.between' => '你是妖怪吗!'
    ];

    public function checkStatus($value)
    {
        if ($value !== 1) {
            return '请选择[启用]用户';
        } else {
           return true;
        }
    }


}


